package com.Fate.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.Fate.common.Constant;
import javafx.scene.chart.LineChart;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkCode.do")
public class CheckCodeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取验证码对象
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(130,50,4,10);
        //将验证码放入session
        String code  = lineCaptcha.getCode();
        req.getSession().setAttribute(Constant.CHECK_CODE_KEY,code);
        //输出到页面
        lineCaptcha.write(resp.getOutputStream());
    }
}
